<?php
 
$db = new Profile();
$table = "user";
$id = $_SESSION['username'];
$nama = strtoupper($_SESSION['nama']);
$profile = $db->lihat($table,$id,"");

if ($profile) {

	if (isset($_GET['success']) && ($_GET['success'] == "1")) {

		$o .= '<div class="alert alert-success">
				Proses tambah berita berhasil
				</div>';
				
	} elseif (isset($_GET['success']) && ($_GET['success'] == "0")) {
		
		$o .= '<div class="alert alert-error">
				Proses tambah berita gagal
			   </div>';
	} elseif (isset($_GET['upload']) && ($_GET['upload'] == "0")) {
		
		$o .= '<div class="alert alert-error">
				Proses upload gambar gagal
			   </div>';
	} elseif (isset($_GET['upload']) && ($_GET['upload'] == "1")) {
		
		$o .= '<div class="alert alert-error">
				Tidak ada yang diupload
			   </div>';
	}

	$o .= '
			<form class="form-horizontal" ENCTYPE="multipart/form-data" id="registerHere" method="post" action="?page=profile&action=edit">
			 <fieldset>
				<legend>PROFILE : '.$nama.' </legend>';
	

	foreach ($profile as $x) {
		$o .= '
				
				<div class="control-group">
				  <label class="control-label" for="input01">NIP</label>
				  <div class="controls">
					<input type="text" class="input-xlarge" id="nip" name="nip" value="'.$x['nip'].'" readonly=readonly>
				  </div>
				</div>
				
				<div class="control-group">
				  <label class="control-label" for="input01">Nama</label>
				  <div class="controls">
					<input type="text" class="input-xlarge" id="nama" name="nama" value="'.$_SESSION['nama'].'" readonly=readonly>
				  </div>
				</div>
				
				<div class="control-group">
				  <label class="control-label" for="input01">Username</label>
				  <div class="controls">
					<input type="text" class="input-xlarge" id="username" name="username" value="'.$_SESSION['username'].'" readonly=readonly>
				  </div>
				</div>
				
				<div class="control-group">
				  <label class="control-label" for="input01">Telepon</label>
				  <div class="controls">
					<input type="text" class="input-xlarge" id="tlp" name="tlp" value="'.$x['telepon'].'" >
				  </div>
				</div>

				<div class="control-group">
				<label class="control-label" for="input01">Tanggal Lahir</label>
				  <div class="controls">
					<input type="text" class="input-xlarge" value="'.$x['tgl_lahir'].'" id="tanggal" name="tanggal" rel="popover" data-content="Masukkan tanggal" data-original-title="Tanggal">
				  </div>
				</div>

				<div class="control-group">
				<label class="control-label" for="input01">Alamat</label>
				  <div class="controls">
					<textarea id="elm1" name="isi" rows="5" cols="40" style="width: 50%">'.html_entity_decode($x['alamat']).'</textarea>
				  </div>
				</div>
				
				<div class="control-group">
					<label class="control-label" for="input01"></label>
					  <div class="controls">
					   <button type="submit" class="btn btn-success" >Ubah Profile</button>
					  </div>
				</div>
				  </fieldset>
			</form>';
	}
} else {
	$o .= '<div class="alert alert-error">
			Data tidak ditemukan
		    </div>';
	
}

$o .= '<a href="?page=home"><i class=" icon-arrow-left"></i> kembali</a>';

echo $o;


if ($_GET['action'] == "add") {
	
	$profile = array ('judul'=>$_POST['judul'], 
					 'tgl'=>$_POST['tanggal'], 
					 'isi'=> htmlentities(mysql_real_escape_string($_POST['isi'])),
					 'gambar'=> $picName, 
					 'nama'=> $_SESSION['username']);

	$addberita = $db->tambah("berita", $berita);

	if ($berita) {
		?>
			<script language="javascript">
			document.location="?page=addberita&success=1";
			</script>
		<?php
		
	} else {
		?>
			<script language="javascript">
			document.location="?page=addberita&success=0";
			</script>
		<?php	
	}
}
